package pipeline.fragment;

import javax.vecmath.Color3f;
import javax.vecmath.Point3f;
import javax.vecmath.Vector2f;
import javax.vecmath.Vector3f;

import pipeline.Pipeline;
import pipeline.misc.Fragment;
import pipeline.misc.FrameBuffer;

public class ReflectionMapFP extends FragmentProcessor {
	
	public int nAttr() {
	    return 9;
	}
	
	public void fragment(Fragment frag, FrameBuffer frameb) {
		if(frag.attrs[0] >  frameb.getZ(frag.x,frag.y))
            return;
		
		Vector3f normal = new Vector3f(frag.attrs[4],frag.attrs[5],frag.attrs[6]);
		normal.normalize();
		int x = (int)((texture.nx/2)*(1+normal.x));
		int y = (int)((texture.ny/2)*(1-normal.y));		  
		Color3f c = new Color3f();
		texture.sample(new Vector2f(x,y), c);
		frameb.set(frag.x, frag.y, c.x, c.y, c.z, frag.attrs[0]);
	}
}
